package com.yugao.fintech.antelope.system.controller;

import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.antelope.system.model.rqrs.article.ArticleGroupListReq;
import com.yugao.fintech.antelope.system.model.rqrs.article.ArticleGroupResp;
import com.yugao.fintech.antelope.system.model.rqrs.article.ArticleGroupSaveReq;
import com.yugao.fintech.antelope.system.model.rqrs.article.ArticleGroupUpdateReq;
import com.yugao.fintech.antelope.system.service.SysArticleGroupService;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "文章组")
@RestController
@RequestMapping("/articleGroup")
public class SysArticleGroupController {
    @Autowired
    private SysArticleGroupService articleGroupService;

    @ApiOperation(value = "分页文章组")
    @GetMapping("/listGroup")
    @RamResource(action = "sys:articleGroup:query", name = "查询文章组", type = ActionType.READ)
    public Resp<List<ArticleGroupResp>> pageGroup(@Validated ArticleGroupListReq req) {
        return Resp.ok(articleGroupService.listGroup(req));
    }

    @ApiOperation(value = "通过id查找文章组")
    @GetMapping("/getGroup")
    @RamResource(action = "sys:articleGroup:query", name = "查询文章组", type = ActionType.READ)
    public Resp<ArticleGroupResp> getGroup(@RequestParam(value = "id") Long id) {
        return Resp.ok(articleGroupService.getGroup(id));
    }
  
    @ApiOperation(value = "保存文章组")
    @PostMapping("/saveGroup")
    @RamResource(action = "sys:articleGroup:save", name = "保存文章组", type = ActionType.WRITE)
    public Resp<?> saveGroup(@Validated @RequestBody ArticleGroupSaveReq req) {
        return Resp.ok(articleGroupService.saveGroup(req));
    }
  
    @ApiOperation(value = "更新文章组")
    @PostMapping("/updateGroup")
    @RamResource(action = "sys:articleGroup:update", name = "更新文章组", type = ActionType.WRITE)
    public Resp<?> updateGroup(@Validated @RequestBody ArticleGroupUpdateReq req) {
        return Resp.ok(articleGroupService.updateGroup(req));
    }
  
    @ApiOperation(value = "批量删除文章组")
    @DeleteMapping("/batchDeleteGroup")
    @RamResource(action = "sys:articleGroup:delete", name = "批量删除文章组", type = ActionType.WRITE)
    public Resp<?> batchDeleteGroup(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(articleGroupService.batchDeleteGroup(ids));
    }
  
    @ApiOperation(value = "删除文章组")
    @DeleteMapping("/deleteGroup")
    @RamResource(action = "sys:articleGroup:delete", name = "删除文章组", type = ActionType.WRITE)
    public Resp<?> deleteGroup(@RequestParam(value = "id") Long id) {
        return Resp.ok(articleGroupService.deleteGroup(id));
    }
}
